<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Dcat\Admin\Traits\HasDateTimeFormatter;

class PayType extends Model
{
    use HasDateTimeFormatter;
    
    protected $table = 'ims_yz_pay_type';
    protected $guarded = [''];
    
    /**
     * 关联订单
     */
    public function orders()
    {
        return $this->hasMany(Order::class, 'pay_type_id', 'id');
    }
    
    /**
     * 获取启用的支付方式
     */
    public function scopeEnabled($query)
    {
        return $query->where('is_enable', 1);
    }
    
    /**
     * 按类型筛选
     */
    public function scopeByType($query, $type)
    {
        return $query->where('type', $type);
    }
}